package com.android.qos;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;

public class UtilActivity extends Activity {
	private static final String LOG_TAG = "util";
	
	public static final String PREFS_SERVER = "MyServer";
	EditText et1, et2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.setting_util);
    	
    	et1 = (EditText)findViewById(R.id.editText1);
    	et2 = (EditText)findViewById(R.id.editText2);
    	
        SharedPreferences serverSetting = getSharedPreferences(PREFS_SERVER, 0);
        String MyIp = serverSetting.getString("IP", "10.4.65.59");
        String MyPort = serverSetting.getString("Port", "8888");
        
        et1.setText(MyIp);
        et2.setText(MyPort);
    }
    
    protected void onStart() {
    	super.onStart();
    	
 
        
    	et1.addTextChangedListener(new TextWatcher(){
    		
			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
	   			Log.d(LOG_TAG, "after : "+ et1.getText());
				
			}
    		
    	});
    	
    	et2.addTextChangedListener(new TextWatcher(){
    		
			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
	   			Log.d(LOG_TAG, "after : "+ et2.getText());
				
			}
    		
    	});



    }
    
    protected void onPause(){
    	super.onPause();
    	
        SharedPreferences settings = getSharedPreferences(PREFS_SERVER, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("IP", et1.getText().toString());
        editor.putString("Port", et2.getText().toString());
        editor.commit();
    }
}
